package TI;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

import Exceptions.NoProductsSelectedException;
import Exceptions.ProductSalesPriceNeverSetException;
import Products.Presentation;
import junit.framework.TestCase;
import static org.mockito.Mockito.*;

public class AnonymusCustomerTest extends TestCase {

	AnonymusCustomer customerToTest = new AnonymusCustomer();
	BranchOffice branchOffice = mock(BranchOffice.class);
	Presentation presentation = mock(Presentation.class);
	Exception exception;
	
	
	@Test
	public void testGivenAnAnonymusCustomerWhenBuyShouldSendSelfAndAListOfProductsToTheBranchOffice() throws ProductSalesPriceNeverSetException{
		List<Presentation> products = new ArrayList<Presentation>();
		products.add(presentation);
		try {
			customerToTest.buy(products, branchOffice);
		} catch (NoProductsSelectedException e) {			
			e.printStackTrace();
		}
		verify(branchOffice).registerQuickBuy(customerToTest, products);
	}
	
	
	@Test
	public void testGivenAnAnonymusCustomerWhenBuyWithAnEmptyProductsShouldRaiseNoProductsSelectedException(){
		List<Presentation> products = new ArrayList<Presentation>();		
		try {
			try {
				customerToTest.buy(products, branchOffice);
			} catch (ProductSalesPriceNeverSetException e) {
				e.printStackTrace();
			}
		} catch (NoProductsSelectedException noProductsSelectedException){
			exception = noProductsSelectedException;
		}		
		assertNotNull(exception);
		assertTrue(exception.getMessage().contains("Products should have at least one presentation"));
	}
	
	
}
